package com.hspedu.list_;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.*;

/**
 * @Author Stringzhua
 * @Date 2024/3/10 21:10
 * description:List的三种遍历方式
 */
public class ListFor {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        //使用LinkedList完成,使用方式和ArrayList一样
//        List list = new ArrayList();
        //List接口的实现子类   Vector LinkedList
//        List list = new Vector();
        List list = new LinkedList();
        list.add("jack");
        list.add("tom");
        list.add("鱼香肉丝");
        list.add("北京烤鸭");
        //三种遍历方式
        System.out.println("=====迭代器=====");
        //1.迭代器
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println("list = " + next);
        }
        System.out.println("=====增强for循环=====");
        //2.增强for循环
        for (Object o : list) {
            System.out.println("list = " + o);
        }
        System.out.println("=====普通for循环=====");
        //3.使用普通for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.println("对象 = " + list.get(i));
        }
    }
}
